const setStyle = (classStyle = []) => {
    const styleSheet = document.createElement("style");
    document.head.appendChild(styleSheet);
    classStyle.forEach(style => {
        styleSheet.sheet.insertRule(style, styleSheet.sheet.cssRules.length);
    });
    return styleSheet;
};

const createStyles = id => [
    `
 #${id} {
    max-width: 80vw;
    color: red;
    border: none;
    border-radius: 10px;
    background-color: #fff;
    user-select: none;
}`,
    `#${id}::backdrop {
    background-color: rgba(0, 0, 0, 0.5);
}`,
    `#${id}:focus {
    outline: none;
}`
];
const createDialog = () => {
    const dialog = document.createElement("dialog");
    const id = "ikun" + Date.now();
    dialog.setAttribute("id", id);
    return dialog;
};

const openDialog = (content = "<h1>FBI WARNING !!!</h1>", closeTime = 3000, callback = () => {}) => {
    const dialog = createDialog();
    dialog.innerHTML = content;
    const styleSheet = setStyle(createStyles(dialog.id));
    document.body.appendChild(dialog);
    dialog.showModal();
    setTimeout(() => {
        callback();
        dialog.close();
        dialog.remove();
        styleSheet.remove();
    }, closeTime);
};

openDialog(`<h1>你好，你的行为已被发现，现已拦截！</h1>`, 3000, () => {
    window.location.href = "https://www.baidu.com";
});
// openDialog();